/*
 * Copyright (c) 2023, 2023,yzc.cn All rights reserved.
 *
 */
package cn.yzc.service.impl;

import cn.yzc.mapper.AttendanceMapper;
import cn.yzc.pojo.Attendance;
import cn.yzc.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalTime;

/**
 * <p>Project: SpringPro - AttendanceServiceImpl</p>
 * <p>Powered by yzc On 2023-10-26 20:17:15</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Service
public class AttendanceServiceImpl implements AttendanceService {
    @Autowired
    AttendanceMapper attendanceMapper;

    /**
     * 上下班打卡
     *
     * @param attendance
     * @return
     */
    @Override
    public int insert(Attendance attendance) {
        LocalTime am = LocalTime.of(9, 00);
        LocalTime pm = LocalTime.of(18, 00);
        LocalTime amTime = attendance.getAmTime();
        LocalTime pmTime = attendance.getPmTime();


        if (amTime.compareTo(am) <= 0) {
            attendance.setAmResults(1); //正常
        } else if (amTime.compareTo(am) > 0) {
            attendance.setAmResults(2);  //迟到
        } else if (amTime == null) {
            attendance.setAmResults(3); //缺勤
        }

        if (pmTime.compareTo(pm) <= 0) {
            attendance.setPmResults(2); //早退
        } else if (pmTime.compareTo(pm) > 0) {
            attendance.setPmResults(1); //正常
        } else if (pmTime == null) {
            attendance.setPmResults(3); //缺勤
        }
        attendanceMapper.insert(attendance);
        return 1;
    }
}
